#include "RsGisLibRegiBasicRegi.h"
#include "ExtensionManager.h"
#include "ExtensionSession.h"
#include <QVariant>

RsGisLibRegiBasicRegi::RsGisLibRegiBasicRegi(RsgisPortal* ClientPortal, QWidget *parent)
{
	ui = new Ui::RsGisLibRegiBasicRegi();
	ui->setupUi(this);

	Portal = ClientPortal;

	connect(ui->pushButton_ReferFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_ReferFilePath_clicked()));
	connect(ui->pushButton_FloatFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_FloatFilePath_clicked()));
	connect(ui->pushButton_OutputFilePath, SIGNAL(clicked()), this, SLOT(on_action_Button_OutputFilePath_clicked()));
	connect(ui->pushButton_Execute, SIGNAL(clicked()), this, SLOT(on_action_Button_Execute_clicked()));

	ui->lineEdit_ReferFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");
	ui->lineEdit_FloatFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\In");
	ui->lineEdit_OutputFilePath->setText("D:\\RS-RPC\\TEST\\IN\\RsGisLib\\Out");

	ui->lineEdit_GCPGap->setText("0");
	ui->lineEdit_MetricThreshold->setText("0.0");
	ui->lineEdit_WindowSize->setText("0");
	ui->lineEdit_SearchArea->setText("0");
	ui->lineEdit_stdDevRefThreshold->setText("0.0");
	ui->lineEdit_stdDevFloatThreshold->setText("0.0");
	ui->lineEdit_subPixelResolution->setText("0");
	ui->lineEdit_MetricTypeInt->setText("0");
	ui->lineEdit_OutputType->setText("0");

	ui->lineEdit_Priority->setText("16");
}

void RsGisLibRegiBasicRegi::on_action_Button_ReferFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_ReferFilePath->setText(str.toUtf8());
}

void RsGisLibRegiBasicRegi::on_action_Button_FloatFilePath_clicked()
{
	QString str = QFileDialog::getOpenFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_FloatFilePath->setText(str.toUtf8());
}

void RsGisLibRegiBasicRegi::on_action_Button_OutputFilePath_clicked()
{
	QString str = QFileDialog::getSaveFileName(this, "File Explorer", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "All file(*.*)");
	ui->lineEdit_OutputFilePath->setText(str.toUtf8());
}

void RsGisLibRegiBasicRegi::on_action_Button_Execute_clicked()
{
	QList<QVariant> SysParaList;
	SysParaList << QVariant(QString("RsGisLib"));
	SysParaList << QVariant(QString("Registration"));
	SysParaList << QVariant(int(ui->lineEdit_Priority->text().toInt()));

	QList<QVariant> AlgParaList;
	AlgParaList << QVariant(QString("BasicRegi"));
	AlgParaList << QVariant(QString(ui->lineEdit_ReferFilePath->text()));
	AlgParaList << QVariant(QString(ui->lineEdit_FloatFilePath->text()));

	AlgParaList << QVariant(int(ui->lineEdit_GCPGap->text().toInt()));
	AlgParaList << QVariant(double(ui->lineEdit_MetricThreshold->text().toDouble()));
	AlgParaList << QVariant(int(ui->lineEdit_WindowSize->text().toInt()));
	AlgParaList << QVariant(int(ui->lineEdit_SearchArea->text().toInt()));
	AlgParaList << QVariant(double(ui->lineEdit_stdDevRefThreshold->text().toDouble()));
	AlgParaList << QVariant(double(ui->lineEdit_stdDevFloatThreshold->text().toDouble()));
	AlgParaList << QVariant(int(ui->lineEdit_subPixelResolution->text().toInt()));
	AlgParaList << QVariant(int(ui->lineEdit_MetricTypeInt->text().toInt()));
	AlgParaList << QVariant(int(ui->lineEdit_OutputType->text().toInt()));

	AlgParaList << QVariant(QString(ui->lineEdit_OutputFilePath->text()));

	QVariantList ArgList;
	ArgList << (QVariant)SysParaList;
	ArgList << (QVariant)AlgParaList;

	Portal->goAhead(ArgList);
}